package com.meituan.catering.management.shop.biz.model.converter;

import com.meituan.catering.management.shop.api.http.model.request.SearchShopHttpRequest;
import com.meituan.catering.management.shop.biz.model.request.SearchShopBizRequest;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Believe
 * Date 2022/5/16 17:48
 */
public class SearchShopBizRequestConverter {
    public static SearchShopBizRequest toSearchShopBizRequest(SearchShopHttpRequest request){
        if (request == null){
            return null;
        }
        SearchShopBizRequest searchShopBizRequest = new SearchShopBizRequest();
        searchShopBizRequest.setPageIndex(request.getPageIndex());
        searchShopBizRequest.setPageSize(request.getPageSize());
        searchShopBizRequest.setKeyword(request.getKeyword());
        searchShopBizRequest.setManagementType(request.getManagementType());
        searchShopBizRequest.setBusinessType(request.getBusinessType());
        searchShopBizRequest.setEnabled(request.getEnabled());
        searchShopBizRequest.setSortFields(toSortField(request.getSortFields()));
        return searchShopBizRequest;
    }

    public static List<SearchShopBizRequest.SortField> toSortField(List<SearchShopHttpRequest.SortField> fieldList){
        List<SearchShopBizRequest.SortField> sortFieldList = new ArrayList<>();
        for (SearchShopHttpRequest.SortField sortField : fieldList) {
            SearchShopBizRequest.SortField field = new SearchShopBizRequest.SortField();
            field.setField(sortField.getField());
            field.setAsc(sortField.getAsc());
            sortFieldList.add(field);
        }
        return sortFieldList;
    }
}
